﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

namespace HZ.Supervise.Web.Admin
{
    public partial class LogList : BasePage
    {
        int totalrecord = 0;
        HZ.Supervise.IBLL.IExecuteContext iStatistics = HZ.Supervise.BLLFactory.ExecuteContext();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Bind();
            }
        }

        /// <summary>
        /// 页面级绑定
        /// </summary>
        public void Bind()
        { 
            DataTable dt = iStatistics.GetLog(str(), this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out totalrecord);
            AspNetPager1.RecordCount = totalrecord;
            gvwInfo.PageSize = AspNetPager1.PageSize;
            gvwInfo.DataSource = dt;
            gvwInfo.DataBind();
        }
        #region 查询条件
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns>where</returns>
        string str()
        {
            StringBuilder sb = new StringBuilder();
            DateTime startime;
            DateTime endtime;
            if (!string.IsNullOrEmpty(txtOperator.Text.Trim()))
            {
                sb.AppendFormat(@"AND CHARINDEX('{0}',Operator)>0", txtOperator.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtStratTime.Text.Trim()))
            {
                startime = (DateTime)new HZ.Common.ConvertHelper(txtStratTime.Text.Trim()).ToDateTime;//开始时间
                sb.AppendFormat(@"  AND OperateTime>='{0}' ", startime);
            }
            if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
            {
                endtime = (DateTime)new HZ.Common.ConvertHelper(txtEndTime.Text.Trim()).ToDateTime;//结束时间

                sb.AppendFormat(@"  AND OperateTime<='{0}' ", endtime.AddMonths(1));
            }
            sb.Append(" order by operatetime desc");
            return sb.ToString();
        }

        #endregion

        /// <summary>
        /// 查询方法
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">参数</param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
        }
        /// <summary>
        /// 导出方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataTable dt = iStatistics.GetLog(str(), 1, 0, out totalrecord);
            if (dt.Rows.Count > 0)
            {
                ExportFile.Instance.ExportData(dt, gvwInfo, this.Page);
            }
            else
            {
                HZ.Web.WebUtil.Alert("暂无导出的数据！", this.Page);
            }
        }

        /// <summary>
        /// 翻页绑定
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">参数</param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Bind();
        }
    }
}